---
title: "Sankey Output"
author: "Yoru"
date: "6 12 2020"
output:
  word_document: default
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
### Religion Data with VDEM
setwd("F:/Workspace/ECPR Draft Religion/Dec 2020 Update")

library(dplyr)

Set.full <- read.csv(file="Change.2000.2014.4V.Auto.csv")

```


```{r Sankey, dpi=300, fig.height=13, fig.width=8}
library(ggplot2)
library(ggalluvial)


ggplot(data = Set.full,
       aes(axis1 = `cluster.a`, axis2 = `cluster.b`, y = count)) +
  scale_x_discrete(limits = c("Year 2000 cluster", "Year 2014 cluster"), expand = c(.1, .1)) +
  xlab("Clusters") +
  geom_alluvium(aes(fill = `cluster.b`)) +
  geom_stratum() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), nudge_x=-.15) +
  geom_text(aes(label = as.character(labels)),
            stat = "flow", size = 3, nudge_x = .04) +
  theme(legend.position = "none") +
  ggtitle("Change in Cluster composition between 2000 and 2014",
          "Total Regulation - 4-Variables - Autocracies")
```

```{r Sankey BW ready, dpi=300, fig.height=13, fig.width=8}
## plot ready for BW transformation
ggplot(data = Set.full,
       aes(axis1 = `cluster.a`, axis2 = `cluster.b`, y = count)) +
  scale_x_discrete(limits = c("Year 2000 cluster", "Year 2014 cluster"), expand = c(.1, .1)) +
  xlab("Clusters") +
  geom_alluvium(aes(fill = `cluster.b`, col=grey(c(0.05)))) +
  geom_stratum() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), nudge_x=-.15) +
  geom_text(aes(label = as.character(labels)),
            stat = "flow", size = 3, nudge_x = .04) +
  theme(legend.position = "none") +
  ggtitle("Change in cluster composition between 2000 and 2014",
          "Autocracies - Total Regulation (4-Variables)")
```


```{r Sankey one-sided, dpi=300, fig.height=13, fig.width=8}
## plot for only joining 2014
ggplot(data = Set.full,
       aes(axis1 = `cluster.a`, axis2 = `cluster.b`, y = count)) +
  scale_x_discrete(limits = c("Year 2000 cluster", "Year 2014 cluster"), expand = c(.1, .1)) +
  xlab("Clusters") +
  geom_alluvium(aes(fill = `cluster.b`)) +
  geom_stratum() +
  scale_fill_identity() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), nudge_x=-.15) +
  geom_text(aes(label = as.character(labels)),
            stat = "flow", size = 3, nudge_x = .04) +
  theme(legend.position = "none") +
  ggtitle("Change in cluster composition between 2000 and 2014",
          "Autocracies - Total Regulation (4-Variables)")
```

